
define(['jquery'], () => {
    class Carousel {
        constructor(selectorNode) {
            this.$ban = $(selectorNode),
            this.$ol = $('#ol'),
            this.$next = $('#next'),
            this.$prev = $('#prev'),
            this.lastindex = 0,
            this.index = 0,
            this.init(),
            this.next()
        }
        //初始ol里li个数
        init() {
            this.$a = this.$ban.children('a')
            this.len = this.$a.length
            for(var i = 0; i < this.len; i++) {
                if(i === 0) {
                    $('<li>').addClass('ac').appendTo(this.$ol)
                } else {
                    $('<li>').appendTo(this.$ol)
                }
            }
            this.$li = this.$ol.children('li')
        }
        
        //向下翻页
        next() {
            this.$next.on('click', () => {
                this.lastindex = this.index;
                this.index++;
                this.index = this.index > (this.len - 1) ? 0 : this.index;
                this.$li.eq(this.lastindex).removeClass('ac');
                this.$li.eq(this.index).addClass('ac');
                // this.$a.eq(this.lastindex).fadeTo(400, 0.4, () => {
                //     this.$a.eq(this.lastindex).removeClass('ac').css({
                //     'opacity': 1
                //      });
                // })
                // this.$a.eq(this.index).addClass('ac')
                this.$a.eq(this.lastindex).fadeOut()
                this.$a.eq(this.index).fadeIn()
                
            })
        }
    }
    return new Carousel('#carousel');
});